﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using BLL.DataContextClasses;

namespace BLL.BusinessClasses
{
    public class AreaAcademica
    {
        //Campos
        private int id;
        private string descripcion;

        //Propiedades
        public int ID
        {
            get { return this.id; }
        }
        public string Descripcion
        {
            get { return this.descripcion; }
            set { this.descripcion = value; }
        }

        //Constructores
        public AreaAcademica(int IDToSearch)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.AreasAcademica Aac = (from a in DB.AreasAcademicas
                                                  where a.ID == IDToSearch
                                                  select a).First();

                this.id = Aac.ID;
                this.descripcion = Aac.Descripcion;
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("No existe tal Area Academica\n" + SqlEx.Message);
            }
        }

        //Metodos
        public static AreaAcademica GetAreaAcademicaByPostgradoID(int PostgradoID)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.Postgrado Pos = (from p in DB.Postgrados
                                                   where p.ID == PostgradoID
                                                   select p).First();

                return new AreaAcademica(Pos.ID_AreaAcademica);
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("Hubo un problema con la base de datos\n" + SqlEx.Message);
            }
        }

        public static AreaAcademica GetAreaAcademicaByCarreraID(int CarreraID)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.Carrera Car = (from c in DB.Carreras
                                                    where c.ID == CarreraID
                                                    select c).First();

                return new AreaAcademica(Car.ID_AreaAcademica);
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("Hubo un problema con la base de datos\n" + SqlEx.Message);
            }
        }
    }
}
